// by Xeno
private ["_vehicle"];
#include "x_setup.sqf"
#include "x_macros.sqf"

#define __Poss _poss = x_sm_pos select 0;
#define __PossAndOther _poss = x_sm_pos select 0;_pos_other = x_sm_pos select 1;

x_sm_pos = [[892.9599,9105.3145,0], [892.23505,9071.9453,0]];  // index: 5,   King of Sedia at hotel in Vallejo
x_sm_type = "normal"; // "convoy"

if (X_Client) then {
	d_current_mission_text = "The king of Hazena is on vacation in a hotel near Pinley. He is a good friend of the enemy leaders. Eliminate him!";
	d_current_mission_resolved_text = "The king of Hazena is dead. Good job.";
};

#ifdef __SMMISSIONS_MARKER__
if (true) exitWith {};
#endif

if (isServer) then {
	__PossAndOther
	__GetEGrp(_newgroup)
	_sm_vehicle = _newgroup createUnit ["King", _poss, [], 0, "FORM"];
	[_sm_vehicle] join _newgroup;
	allunits_add set [count allunits_add, _sm_vehicle];
	#ifndef __TT__
	_sm_vehicle addEventHandler ["killed", {_this call XKilledSMTargetNormal}];
	#endif
	#ifdef __TT__
	_sm_vehicle addEventHandler ["killed", {_this call XKilledSMTargetTT}];
	#endif
	// hotel has 266 building positions
	_nbuilding = nearestBuilding _sm_vehicle;
	// these are hotel positions in rooms with no door !!!!
	_no_list = [86,87,88,89,148,149,150,151,177,178,179,188,189,190];//,200,201,202];//,210,211,212,213,215,216,217];//230,231,232,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,262,263,264,265];
	//_no_list = [86,87,88,89,148,149,150,151,210,211,212,213,262,263,264,265];		
	_bpos = floor random 200;
	while {_bpos in _no_list} do {_bpos = floor random 200;};
	_sm_vehicle setPos (_nbuilding buildingPos _bpos);
	sleep 2.123;
	_grps = ["specops", 1, "basic", 2, _poss,0] call XCreateInf;
	{
		_unitsg = units _x;
		{
			_bpos = floor random 266;
			while {_bpos in _no_list} do {_bpos = floor random 200;};
			_x setPos (_nbuilding buildingPos _bpos);
			_x disableAI "MOVE";
		} forEach _unitsg;
		sleep 0.01;
	} forEach _grps;
	sleep 2.222;
	["shilka", 1, "bmp", 1, "tank", 1, _pos_other,1,80,true] spawn XCreateArmor;
	_leader = leader _newgroup;
	_leader setRank "COLONEL";
	_newgroup allowFleeing 0;
	_newgroup setbehaviour "AWARE";
};

if (true) exitWith {};